import { Module } from '@nestjs/common';
import { UserClientController } from './user-client.controller';
import { UserClientService } from './user-client.service';
import { DbModule } from './db/db.module';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { CacheModule } from '@app/cache';
import { UserModule } from './http/user/user.module';
import { LoginModule } from './http/login/login.module';
import { ScheduleModule } from './schedule/schedule.module';
import { WechatModule } from '@app/wechat';
import { DbService } from './db/db.service';
import { SYS_CONFIG } from 'constant/SYS_CONFIG';
import { RechargeModule } from './http/recharge/recharge.module';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from './guard/auth/auth.guard';
import { DeviceModule } from './http/device/device.module';
import { TestModule } from './http/test/test.module';
import { AlicloudModule } from '@app/alicloud';
import { WaterBillsModule } from './http/water-bills/water-bills.module';
import { WaterTestModule } from './http/water-test/water-test.module';
import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';
import config from './config'
import { UploadModule } from './http/upload/upload.module';


@Module({
	imports: [
		ConfigureModule.forRoot(config),
        DbModule,
		CacheModule,
        WechatModule.forRootAsync({
			inject : [DbService],
			useFactory : async (db:DbService) => {
                const configs = await db.sysConfig.selectValues(SYS_CONFIG.wechat)
				return {appid : configs[SYS_CONFIG.appid], secret : configs[SYS_CONFIG.secret], mchid : configs[SYS_CONFIG.mchid], v3Key : configs[SYS_CONFIG.v3Key], publicKey : configs[SYS_CONFIG.publicKey], privateKey : configs[SYS_CONFIG.privateKey], baseNotifyUrl : configs[SYS_CONFIG.baseNotifyUrl]}
			}
		}),


		AlicloudModule.forRootAsync({
			inject : [ConfigureService],
			useFactory : async (config:ConfigureService) => {
				return {
					...config.get('alicloud')
				}
			},
		
			// dataSourceFactory: async (options) => {
			// 	const dataSource = await new DataSource(options).initialize();
			// 	return dataSource;
			// },
		}),
		SysConfigRepositoryModule,
        UserModule, LoginModule, ScheduleModule, RechargeModule, DeviceModule, TestModule, WaterBillsModule, WaterTestModule, WechatModule, UploadModule],
	controllers: [UserClientController],
	providers: [UserClientService, {provide : APP_GUARD, useClass : AuthGuard}],
})
export class UserClientModule {}
